const {Sequelize, DataTypes} = require("sequelize");
const start = require("./utils/connect");

(async()=>{
  const sequelize = await start();
  const Club = sequelize.define("Club",{
    name:{
      type:DataTypes.STRING,
      allowNull:false
    },
    member:{
      type:DataTypes.INTEGER.ZEROFILL
    }
  },{
    freezeTableName:true // 强制使用定义表名
  });

  const Manager = sequelize.define("Manager",{
    name:{
      type:DataTypes.STRING
    },
    age:{
      type:DataTypes.INTEGER,
      defaultValue:24
    },
    uuid:{
      type:DataTypes.UUID,
      defaultValue:Sequelize.UUIDV4
    }
  });

  Club.hasOne(Manager);


  await Manager.sync({
    alter:true,
  });
  await Club.sync({
    alter:true,
  });
  



  // const IG = await Club.create({name:"IG"});
  // const askwan = await Manager.create({name:"askwan"});
  
  // await IG.setManager(askwan);

  // const TES = await Club.create({name:"TES"});
  // TES.createManager({name:"hong mi"});

  const club = await Club.findByPk(2);
  const manager = await club.getManager();
  console.log("Club:",club.toJSON());
  console.log("manager:",manager.toJSON());


})();